$.extend({
    accordion: function (data,url) {
        var accordion = $('#accordion');
        $.each(data, function (index,info) {
            var li = $('<li></li>');
            li.html('<a class="link" href="#">'+info['cname']+'<span class="glyphicon glyphicon-chevron-down fa"></span></a>');
            var ul = $('<ul class="submenu"></ul>');
            $.each(info['child'], function (index, info) {
                var link = $('<li></li>');
                link.html('<a href='+url+'?cid='+info['cid']+'>'+info['cname']+'</a>');
                ul.append(link);
            })
            li.append(ul);
            accordion.append(li);
        })

        var Accordion = function(el, multiple) {
            this.el = el || {};
            this.multiple = multiple || false;

            // Variables privadas
            var links = this.el.find('.link');
            // Evento
            links.on('click', {el: this.el, multiple: this.multiple}, this.dropdown)
        }

        Accordion.prototype.dropdown = function(e) {

            var $el = e.data.el;
            $this = $(this),
                $next = $this.next();

            $next.slideToggle();
            $this.parent().toggleClass('open');


            if (!e.data.multiple) {
                $el.find('.submenu').not($next).slideUp().parent().removeClass('open');
            };
        }
        accordion = new Accordion($('#accordion'), false);
    }
})